home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / pctj1086.arc / DRAWPOLY.MOD < prev    next >
Text File  |  1986-07-21  |  2KB  |  58 lines

  1. IMPLEMENTATION MODULE DrawPoly;
  2. (*
  3. Title   : DrawPoly.MOD -- Draw lines and boxes
  4. LastEdit: July 22, 1986
  5. Author  : John T. Cockerham, M.D.
  6. System  : LOGITECH MODULA-2/86 
  7. *)
  8.   FROM LowEGA IMPORT DrawPoint;
  9.   FROM PointLib IMPORT Point;
  10.   
  11.   PROCEDURE DrawLine(p1, p2 : Point; color : CARDINAL);
  12.     (* Brensheman's Algorithm for drawing a line from
  13.        p1 to p2. *)
  14.     VAR deltax, deltay, xup, yup, supx, supy,
  15.         temp, corrs, corrd, direction, maxdim, i : INTEGER;
  16.         a : Point;
  17.   BEGIN
  18.     xup := 1;  yup := 1;
  19.     deltax := p2.x-p1.x;  deltay := p2.y-p1.y;
  20.     IF deltax < 0 THEN xup := -1; deltax := -deltax;  END;
  21.     IF deltay < 0 THEN yup := -1; deltay := -deltay;  END;
  22.     supx := xup;  supy := yup;   maxdim := deltax;
  23.     IF deltax < deltay THEN
  24.       maxdim := deltay;      supx := 0;
  25.       temp := deltax;        deltax := deltay;
  26.       deltay := temp;
  27.     ELSE
  28.       supy := 0;
  29.     END;
  30.     corrs := 2 * deltay;  corrd := 2 * (deltay - deltax);
  31.     direction := (2 * deltay) - deltax;
  32.     a := p1;
  33.     FOR i := 1 TO maxdim DO
  34.       DrawPoint(a, color);
  35.       IF direction >= 0 THEN
  36.         a.x := a.x + xup;  a.y := a.y + yup;
  37.         direction := direction + corrd;
  38.       ELSE
  39.         a.x := a.x + supx; a.y := a.y + supy;
  40.         direction := direction + corrs;
  41.       END;
  42.     END;
  43.   END DrawLine;
  44.  
  45.   PROCEDURE DrawBox(UpperLeft, LowerRight : Point; c : CARDINAL);
  46.     (* Draw a Box with the two points specifying two opposite
  47.        corners. Color the lines according to palette c *)
  48.     VAR    p1, p2 : Point;
  49.   BEGIN
  50.     p1 := UpperLeft;  p2 := LowerRight;     p2.x := UpperLeft.x;
  51.     DrawLine(p1, p2, c);
  52.     p2 := LowerRight; p2.y := UpperLeft.y;  DrawLine(p1, p2, c);
  53.     p1 := LowerRight; p2 := UpperLeft;      p2.x := LowerRight.x;
  54.     DrawLine(p1, p2, c);
  55.     p2 := UpperLeft;  p2.y := LowerRight.y; DrawLine(p1, p2, c);
  56.   END DrawBox;
  57. END DrawPoly.
  58.